const {
	findOrders,
	addOrder
} = require('../service/order.service')
const {getFoodInfoById} = require('../service/food.service')

class OrderController{

	async findAll(ctx){

		const {pageNum = '1',pageSize = '10'} = ctx.request.query
		const res = await findOrders(pageNum,pageSize)

		ctx.body = {
			res
		}
	}

	async addOrders(ctx){
		const food_id = ctx.request.query.id
		const {num,status} = ctx.request.body
		const {food_name,price,address} = await getFoodInfoById(food_id)
		const {id,user_name} = ctx.state.user
		const order_id = 'YCU' + Date.now()
		const res = await addOrder(order_id,food_id,{food_name,price,address},{id,user_name},{num,status})
		ctx.body = {
			res
		}
	}
}

module.exports = new OrderController()